package com.fantastic.common.utils;

import com.fantastic.common.exception.AbstractMyException;

import java.util.List;


/**
 * @author: rxx
 * @since: 2024/5/30 10:55
 * @description: 判断数据是否合法工具类
 */
public class IsEmptyUtils {

    /**
     * 判断集合是否为空
     *
     * @param list                list集合
     * @param abstractMyException 抽象的我的自定义异常对象
     * @param <T>
     */
    public static <T> void listIsEmpty(AbstractMyException abstractMyException, List<T> list) {
        if (list.size() == 0) {
            //抛出异常
            throw abstractMyException;
        }
    }

    /**
     * 判断字符串是否为空或是'空字符串
     *
     * @param abstractMyException 抽象的我的自定义异常对象
     * @param str                 要判断的字符串
     */
    public static void stringIsEmpty(AbstractMyException abstractMyException, String... str) {
        for (int i = 0; i < str.length; i++) {
            if (str[i] == null || str[i] == "") {
                throw abstractMyException;
            }
        }
    }

    /**
     * 判断Integer数值是否为空
     *
     * @param abstractMyException 抽象的我的自定义异常对象
     * @param number              要判断的数值
     */
    public static void integerIsEmpty(AbstractMyException abstractMyException, Integer... number) {
        for (int i = 0; i < number.length; i++) {
            if (number[i] == null) {
                throw abstractMyException;
            }
        }
    }
    /**
     * 判断Long数值是否为空
     *
     * @param abstractMyException 抽象的我的自定义异常对象
     * @param number              要判断的数值
     */
    public static void longIsEmpty(AbstractMyException abstractMyException, Long... number) {
        for (int i = 0; i < number.length; i++) {
            if (number[i] == null) {
                throw abstractMyException;
            }
        }
    }

    /**
     * 判断对象是否为空
     *
     * @param abstractMyException 抽象的我的自定义异常对象
     * @param object              要判断的数值
     */
    public static void objectIsNull(AbstractMyException abstractMyException, Object... object) {
        for (int i = 0; i < object.length; i++) {
            if (object[i] == null) {
                throw abstractMyException;
            }
        }
    }


}
